package top.ruanlitao.shortlink.project.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import top.ruanlitao.shortlink.project.mq.producer.ShortLinkStatsSaveProducer;

/**
 * 消息队列配置类
 */
@Configuration
public class MessageQueueConfig {

    @Value("${short-link.message-queue.type:rocketmq}")
    private String messageQueueType;

    @Bean
    @Primary
    public ShortLinkStatsSaveProducer shortLinkStatsSaveProducer(
            ShortLinkStatsSaveProducer redisShortLinkStatsSaveProducer,
            ShortLinkStatsSaveProducer rocketMQShortLinkStatsSaveProducer) {
        // 根据配置选择使用哪个消息队列实现
        return switch (messageQueueType.toLowerCase()) {
            case "redis" -> redisShortLinkStatsSaveProducer;
            case "rocketmq" -> rocketMQShortLinkStatsSaveProducer;
            default -> rocketMQShortLinkStatsSaveProducer; // 默认使用 RocketMQ
        };
    }
} 